class Booktable < ActiveRecord::Base
validates :nameBook, :nameAuthor,:quantity ,:typeBook, :image, :decription, :presence => true
  validates :quantity, :numericality => {:greater_than => 0}
  validates :image, :format => {
          :with => %r{\.(gif|jpg|png|jpeg)$}i
          
    }
  	def self.search(search)
        if search
      		find(:all, :conditions => ['booktables.nameBook LIKE ?', "%#{search}%"]) #, :order => 'products.product_id DESC')
        else
            find(:all)
        end
    end

 	def self.searchByAuthor(searchByAuthor)
        if searchByAuthor
        	find(:all, :conditions => ['booktables.nameAuthor LIKE ?', "%#{searchByAuthor}%"])
        else
        	find(:all)
        end
    end

    def self.searchByCategory(searchByCategory)
        if searchByCategory
        	find(:all, :conditions => ['booktables.typeBook LIKE ?', "%#{searchByCategory}%"])
        else
        	find(:all)
        end
    end
 
  
end
